package com.qf.aop;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.Date;

@Component
@Aspect
public class TestAop {
    @Pointcut("execution(* com.qf.service..*.*(..))")
    public void  pc(){}
    @Around("pc()")
    public Object around(ProceedingJoinPoint joinPoint){

        try {
            System.out.println("前置增强");
            //执行原始方法
            Object result = joinPoint.proceed();

            System.out.println("时间：[" +  LocalDate.now()+"] 调用了 ["+ joinPoint.getTarget().getClass()
               +"] 方法：["+joinPoint.getSignature().getName()+"]，参数列表为：["
                + Arrays.toString(joinPoint.getArgs())+"]");

            System.out.println("后置增强");
            return result;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println("异常增强");
        } finally {
            System.out.println("最终增强");
        }
        return null;
    }
}
